package com.health.pay.tencent.protocol.closeorder;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.health.pay.tencent.common.Configure;
import com.health.pay.tencent.common.Signature;
import com.health.pay.tencent.protocol.BaseReqData;

public class CloseOrderReqData extends BaseReqData{

	private String appid;
	private String mch_id;
	private String out_trade_no;
	private String nonce_str;
	private String sign;
	public CloseOrderReqData(String outTradeNo, String nonceStr) {
		super();
		setAppid(Configure.getAppid());
		setMch_id(Configure.getMchid());
		setOut_trade_no(outTradeNo);
		setNonce_str(nonceStr);
        String sign = Signature.getSign(toMap());
        setSign(sign);
	}
	public String getAppid() {
		return appid;
	}
	public void setAppid(String appid) {
		this.appid = appid;
	}
	public String getMch_id() {
		return mch_id;
	}
	public void setMch_id(String mchId) {
		mch_id = mchId;
	}
	public String getOut_trade_no() {
		return out_trade_no;
	}
	public void setOut_trade_no(String outTradeNo) {
		out_trade_no = outTradeNo;
	}
	public String getNonce_str() {
		return nonce_str;
	}
	public void setNonce_str(String nonceStr) {
		nonce_str = nonceStr;
	}
	public String getSign() {
		return sign;
	}
	public void setSign(String sign) {
		this.sign = sign;
	}
	
	@Override
	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			Object obj;
			try {
				obj = field.get(this);
				if (obj != null) {
					map.put(field.getName(), obj);
				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return map;
	}
	
}
